package bigraph.model;

import java.util.Iterator;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;



public class Place extends Node {

	public static final String PROPERTY_COLOR = "PlaceColor";
	private Color background;
	
	public Place() {
		super();
		this.background = ColorConstants.white;
	}
	
    public void setColor(Color color) {
    	Color oldColor = background;
    	this.background = color;
    	getListeners().firePropertyChange(PROPERTY_COLOR, oldColor, color);
    }
    
    public Color getColor() {
    	return background;
    }
    
	@Override
	public Object clone() throws CloneNotSupportedException {
	     Place pl = new Place();
	     pl.setName(this.getName());
         pl.setColor(this.background);
	     pl.setParent(this.getParent());
	     pl.setLayout(new Rectangle(
	                 getLayout().x + 10, getLayout().y + 10,
	                 getLayout().width, getLayout().height));
	     Iterator<Node> it = this.getChildrenArray().iterator();
	     while (it.hasNext()) {
	           Node node = it.next();
	           if (node instanceof Site) {
	                 Site child = (Site)node;
	                 Node clone = (Node)child.clone();
	                 pl.addChild(clone);
	                 clone.setLayout(child.getLayout());
	           }
	           else if (node instanceof Place) {
	                 Place child = (Place)node;
	                 Node clone = (Node)child.clone();
	                 pl.addChild(clone); 
	                 clone.setLayout(child.getLayout());
	           }
	     }
	     return pl;
	}

}